<?php
/*
 *  this is a convenient sql wrapper
 *
 */

	function sqlInit($db = "killerpixel"){
		$user="killerpixel";
		$password="anaarelene";
		$database="".$db;
		mysql_connect("localhost",$user,$password);
		@mysql_select_db($database) or die( "Unable to select database");
                mysql_set_charset ("UTF8");
	}
	function sqlQuery($query,$columns = array(),$debug = 0){
		$result = mysql_query($query.";");
		if(! $result || $result == 1 || $result == 2) return array();
		$num = mysql_numrows($result);
		$ret = array();
		if($debug || isset($_GET["deb"])) echo "query: \"" . $query . "\" - " . $num . " rows <br/>";
		for($i = 0;$i<$num;$i++){
			foreach($columns as $value){
				$ret[$i][$value] = mysql_result($result,$i,$value);
				if($debug || isset($_GET["deb"])) echo $value . " : " . $ret[$i][$value] . "; ";
			}
			$ret[$i][0] = true;
			if($debug || isset($_GET["deb"])) echo "<br/>";
		}
		return $ret;
	}
	function sqlQueryDebug($query,$columns = array()){
		$ret = sqlQuery($query,$columns,true);
		return $ret;
	}
	function sqlClose(){
		@mysql_close();
	}

?>
